package com.kt.delivery.utils;

import com.kt.delivery.config.WxPayConfig;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * @ClassName test
 * @Description TODO
 * @Author ghs
 * @Date 2024-04-03 14:47
 * @Version 1.0
 */
public class test {

    /** 商户号 */
    public static String merchantId = "1651546443";
    /** 商户API私钥路径 */
    public static String privateKeyPath = "C:\\Users\\ghs\\Desktop\\1651546443_20240402_cert\\apiclient_key.pem";
    /** 商户证书序列号 */
    public static String merchantSerialNumber = "5EC52E909AC277E9EAD45CC2BBF3955970F7F0DC";
    /** 商户APIV3密钥 */
    public static String apiV3Key = "20230827202308272023082720230827";

    /** appId */
    public static String appId = "wx1cab9cfdaf692e86";

    public static String openId= "od_9-67orCuP4l2WJfXYRlL4hdZM";

    public static void main(String[] args) {
        // 使用自动更新平台证书的RSA配置
        // 一个商户号只能初始化一个配置，否则会因为重复的下载任务报错
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(merchantId)
                        .privateKeyFromPath(privateKeyPath)
                        .merchantSerialNumber(merchantSerialNumber)
                        .apiV3Key(apiV3Key)
                        .build();
        // 构建service
        JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
        // request.setXxx(val)设置所需参数，具体参数可见Request定义
        PrepayRequest request = new PrepayRequest();
        Amount amount = new Amount();
        amount.setTotal(100);
        request.setAmount(amount);
        request.setAppid(appId);
        request.setMchid(merchantId);
        request.setDescription("测试商品标题");
        request.setNotifyUrl("http://121.36.27.229:8888/4eb75206");
        request.setOutTradeNo("out_trade_no_001");
        Payer payer = new Payer();
        payer.setOpenid(openId);
        request.setPayer(payer);

        // 调用下单方法，得到应答
        PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);

        System.out.println(response);
    }
}
